#include "fletcher16.h"

#define MOD_FLETCHER 255U

uint16_t MakeFletcher16(uint8_t *inData, size_t length)
{
    uint32_t sum1 = 0;
    uint32_t sum2 = 0;

    while (length-- > 0) {
        sum1 = (sum1 + *inData++) % MOD_FLETCHER;
        sum2 = (sum2 + sum1) % MOD_FLETCHER;
    }

    return (uint16_t)((sum2 << 8) | sum1);
}

